const Koa = require('koa');
const proxy = require('koa2-proxy-middleware');
const bodyparser = require('koa-bodyparser');
const static = require("koa-static");
const proxyConf = require("./proxy.conf.json");
const app = new Koa();
 
const options = {
  targets: {
    ...proxyConf,
    
    '/api/(.*)': {
      // this is option of http-proxy-middleware
      target: 'https://test.tedianren.com', // target host
      changeOrigin: true, // needed for virtual hosted sites
    },
    '/basic-api': {
      target: 'http://localhost:3001',
      changeOrigin: true,
    },
    '/upload': {
      target: 'http://localhost:3300/upload',
      changeOrigin: true,
    },
    // (.*) means anything
    // '/api/(.*)': {
    //   target: 'http://10.94.123.123:1234',
    //   changeOrigin: true,
    //   pathRewrite: {
    //     '/passager/xx': '/mPassenger/ee', // rewrite path
    //   }
    // },
  }
}

app.use(static("./dist"));

app.use(proxy(options));

app.use(bodyparser())

app.listen(3000);